<%--
  Created by IntelliJ IDEA.
  User: hxh
  Date: 16/4/23
  Time: 下午2:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
  <title>添加新闻</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <link href="/static/bui/css/bs3/dpl.css" rel="stylesheet" type="text/css"/>
  <link href="/static/bui/css/bs3/bui.css" rel="stylesheet" type="text/css"/>
  <link href="../../../../ueditor/themes/default/css/ueditor.css" type="text/css" rel="stylesheet">
  <script type="text/javascript" src="/static/bui/js/jquery-1.8.1.min.js"></script>
  <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.js"></script>
  <script type="text/javascript" src="/static/bui/js/bui.js"></script>
</head>
<body>

<div class="content" style="margin: 15px">


  <!-- 搜索页 ================================================== -->

  <div class="search-grid-container">
    <div id="grid">
    </div>

  </div>

  <script type="text/javascript">

    // 定义UEditor对应的主目录
    window.UEDITOR_HOME_URL = "${contextPath}/ueditor/";
    // 页面加载完成后载入UEditor
    window.onload = function () {
      window.UEDITOR_CONFIG.initialFrameWidth = 1010;
      window.UEDITOR_CONFIG.initialFrameHeight = 600;
      UE.getEditor('container');
      UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
      UE.Editor.prototype.getActionUrl = function (action) {
        if (action == "uploadimage") {
          return "/news/uploadImage";
        } else {
          return this._bkGetActionUrl.call(this, action);
        }
      }
    }

    BUI.use('common/search', function (Search) {
      var enumObj = {"1": "参会地址", "2": "酒店交通"},
              enumObj1 = {"1": "是", "2": "否"};

      var columns = [
        {title: 'ID', width: 100, sortable: true, dataIndex: 'id'},
        {
          title: '描述',
          width: 100,
          sortable: true,
          dataIndex: 'type',
          renderer: BUI.Grid.Format.enumRenderer(enumObj)
        },
        {
          title: '创建日期',
          sortable: true,
          dataIndex: 'created',
          width: 150,
          renderer: BUI.Grid.Format.datetimeRenderer
        },
        {
          title: '状态',
          width: 100,
          sortable: true,
          dataIndex: 'status',
          renderer: BUI.Grid.Format.enumRenderer(enumObj1)
        },
        {
          title: '操作', width: 300, dataIndex: 'g', renderer: function (value, obj) {
          var editStr = '<a href="/guide/add/' + obj._id + '" ><span class="grid-command btn-edit" title="编辑信息">编辑</span></a>'
          return editStr
        }
        }
      ]
      var store = Search.createStore('/guide/list.json', {
                autoSync: true,
                pageSize: 10
                //保存数据后，自动更新
              }),
              gridCfg = Search.createGridCfg(columns, {
                tbar: {
                  items: [
                    {
                      text: '<i class="icon-plus"></i>新建',
                      btnCls: 'button button-small',
                      handler: addFunction
                    },
                    {
                      text: '<i class="icon-remove"></i>删除',
                      btnCls: 'button button-small',
                      handler: delFunction
                    }
                  ]
                },
                plugins: [BUI.Grid.Plugins.CheckSelection, BUI.Grid.Plugins.AutoFit] // 插件形式引入多选表格
              });

      var search = new Search({
                store: store,
                gridCfg: gridCfg
              }),
              grid = search.get('grid');

      function addFunction() {
        window.location.href = '/guide/add/0'
      }

      //删除操作
      function delFunction() {
        var selections = grid.getSelection();
        delItems(selections);
      }

      function delItems(items) {
        var ids = [];
        BUI.each(items, function (item) {
          ids.push(item.id);
        });

        if (ids.length) {
          BUI.Message.Confirm('确认要删除选中的记录么？', function () {
            $.ajax({
              url: './delete.json',
              dataType: 'json',
              data: {ids: ids.toString()},
              type: "POST",
              success: function (data) {
                if (data.code == 2000) {
                  search.load()
                } else {
                  BUI.Message.Alert("删除失败")
                }
              }
            })
          }, 'question');
        }
      }

    })
  </script>
</div>
</body>
</html>
